package com.crm.controller.after_sale;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.pojo.ClientCare;
import com.crm.pojo.Userinfo;
import com.crm.service.after_sale.ClientCareService;
import com.crm.service.client.ClientInfoService;
import com.crm.vo.ClientCareAndContact;
import com.crm.vo.Result;

@Controller
public class ClientCareController {

	@Autowired
	private ClientCareService clientCareService;
	@Autowired
	public ClientInfoService clientInfoService;
	/**
	 * 转到关怀页面
	 * @return
	 */
	@GetMapping("/client-care")
	public String clientCare() {
		return "after-sale/client-care";
	}
	/**
	 * 转到客户关怀表单页面
	 * @return
	 */
	@GetMapping("/client-care-form")
	public String clientCareForm() {
		return "after-sale/client-care-form";
	}
	
	/**
	 *  转到编辑客户关怀表单页面
	 * @return
	 */
	@GetMapping("/edit-client-care-form")
	public String editClientCareForm() {
		return "after-sale/edit-client-care-form";
	}
	
	/**
	 *  转到客户关怀视图页面
	 * @return
	 */
	@GetMapping("/view-client-care-form")
	public String viewClientCareForm() {
		return "after-sale/view-client-care-form";
	}
	
	
	/**
	 * 分页查询所有的没有被删除的客户关怀
	 * @param page
	 * @param rows
	 * @return
	 */
	@PostMapping("/find-all-care-notDel-by-page")
	@ResponseBody
	public Map findAllCareNotDelByPage(int page, int rows) {
		Long total = clientCareService.countAllNotDelByPage();
		List<ClientCareAndContact> clientCareAndContacts = clientCareService.findAllNotDelByPage(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", clientCareAndContacts);
		return map;
	}
	/**
	 * 根据客户关怀编号查询没有被删除的客户关怀
	 * @param careid
	 * @param page
	 * @param rows
	 * @return
	 */
	@PostMapping("/find-care-by-careid")
	@ResponseBody
	public Map findCareByCareid(Long careid, int page, int rows) {
		Long total = clientCareService.countCareByCareid(careid);
		List<ClientCareAndContact> clientCareAndContacts = clientCareService.findCareByCareid(careid, page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", clientCareAndContacts);
		return map;
	}
	
	/**
	 * 根据客户关怀主题查询没有被删除的客户关怀
	 * @param careTheme
	 * @param page
	 * @param rows
	 * @return
	 */
	@PostMapping("/find-care-by-careTheme")
	@ResponseBody
	public Map findCareByCareTheme(String careTheme, int page, int rows) {
		Long total = clientCareService.countCareByCareTheme(careTheme);
		List<ClientCareAndContact> clientCareAndContacts = clientCareService.findCareByCareTheme(careTheme, page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", clientCareAndContacts);
		return map;
	}
	
	/**
	 * 删除客户关怀
	 * @param careid
	 * @return
	 */
	@PostMapping("/del-clientCare")
	@ResponseBody
	public Result delClientCare(Long careid) {
		return clientCareService.delClientCare(careid);
	}
	
	/**
	 * 新增客户
	 * @param clientCare
	 * @return
	 */
	@PostMapping("/add-clientCare")
	@ResponseBody
	public Result addClientCare(ClientCare clientCare) {
		return clientCareService.addClientCare(clientCare);
	}
	
	/**
	 * 查询所有的用户
	 * @return
	 */
	@PostMapping("/care-query-all-user")
	@ResponseBody
	public List<Userinfo> queryAllUser(){
		return clientInfoService.queryAllUser();
	}
	
	/**
	 * 编辑客户关怀
	 * @param clientCare
	 * @return
	 */
	@PostMapping("/edit-clientCare")
	@ResponseBody
	public Result editClientCare(ClientCare clientCare) {
		return clientCareService.editClientCare(clientCare);
	}
	
}
